package com.itheima.Test22;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class UploadClient {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);

        Socket socket = new Socket("127.0.1.0", 10000);

        FileInputStream fis;
        while (true) {
            System.out.println("请输入上传文件的路径:");
            String line = sc.next();
            if (line.equals("Test02\\JavaWEB.jpg")) {
                fis = new FileInputStream(line);
                break;
            } else {
                System.out.println("请输入正确的图片文件路劲,请重新输入");
            }
        }

        OutputStream os = socket.getOutputStream();
        int i;
        byte[] bytes = new byte[1024];
        while ((i = fis.read(bytes)) != -1) {
            os.write(bytes, 0, i);
        }
        socket.shutdownOutput();

        InputStream is = socket.getInputStream();
        int b = is.read(bytes);
        System.out.println("服务器的反馈:" + new String(bytes, 0, b));

        fis.close();
        socket.close();
    }
}
